package com.cn.jsdr.service.serviceImpl;

import com.cn.jsdr.common.SqlConfig;
import com.cn.jsdr.service.AddService;
import com.cn.jsdr.service.RediService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AddServiceImpl implements AddService {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private RediService rediService;

    @Override
    public int insert(String sqlid , Map<String, Object> map){
        Map m = rediService.getSql(sqlid);
        String sql = SqlConfig.getAddSql(m,map);
        return jdbcTemplate.update(sql);
    }

    @Override
    public int inserts(String sqlid, List<Map<String, Object>> map) {
        Map m = rediService.getSql(sqlid);
        String sql = SqlConfig.getAddSqls(m,map);
        return jdbcTemplate.update(sql);
    }

    @Override
    public void BatchInsert(String sqlid, List<Map<String, Object>> map) {
        Map m = rediService.getSql(sqlid);
        String sqls[] = SqlConfig.getBatchSqls(m,map);
        for(String sql:sqls ){
            jdbcTemplate.update(sql);
        }
    }
}
